<template>
  <div class="page">
    <c-title :hide="false" text="预约信息"></c-title>
    <van-field v-model="form.date" is-link readonly label="预约时间" placeholder="请选择预约时间" @click="datecli" />
    <div class="time">
      <van-datetime-picker title="选择时间" :min-date="NowDate" :max-date="maxDate" v-model="currentDate" type="date" @confirm="onConfirm" @cancel="dateshow = false" />
      <!-- <van-popup v-model:show="dateshow" position="bottom">
    </van-popup> -->

      <div class="submit" @click="submit">立即预约</div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  data() {
    return {
      NowDate: new Date(),
      currentDate: new Date(),
      datavalue:null,
      form: {
        date: null,
        dateshow: true,
        llid: ""
      }
    };
  },
  activated() {
    this.llid = this.$route.query.llid;
  },
  methods: {
    datecli() {
      this.dateshow = true;
    },
    formatDate(datavalue) {
      return `${datavalue.getFullYear()}/${datavalue.getMonth() + 1}/${datavalue.getDate()}`;
    },
    submit() {
      if(this.form.date!=""){
         $http.post("plugin.store-cashier.frontend.store.store-technician.add_yuyue", {
          store_id: 28,
          yuyue_time: this.form.date,
          project_id: this.llid
        })
        .then(response => {
          if (response.result == 1) {
            Toast(response.msg);
            this.$router.go(-1);
          }
        });
      }else{
        Toast("请先选择预约时间")
        return
      }
      
    },
    onConfirm(datavalue) {
      this.dateshow = false;
      this.form.date = this.formatDate(datavalue);
    }
  }
};
</script>

<style scoped lang="scss">
.time {
  margin-top: 3rem;
}
.submit {
  background-color: #027afe;
  color: #fff;
  line-height: 2rem;
  margin-top: 10rem;
  // position: absolute;bottom: 2rem;
  // width: 100%;
}
</style>
